/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GameHallServer;

import GameHallDBController.HallDeskDB;
import WebServiceDBController.GamingStateDB;
import WebServiceModel.GamingStateModel;
import java.util.ArrayList;
import GameHallDeskModel.*;
import seGobangServer.DBController.*;
import seGobangServer.Model.*;

/**
 *
 * @author Peach
 */
public class GameHallServer {
    
    public ArrayList<Integer> checkDesk(int room, int desk, int id){
    
        HallDeskDB db=new HallDeskDB();
        HallDeskModel model=db.getDeskInfo(room, desk);
        
        ArrayList<Integer> result=new ArrayList<Integer>();
        result.add(model.getPlayers());
        result.add(model.getPlayerA());
        result.add(model.getPlayerB());
        
        return result;        
    }
    
    public ArrayList<String> getOpponent(int detail){
    
        UserController db=UserController.getInstance();
        User user=User.getInstance();        
        user.SetDetail(detail+"");
        db.GetWinsAndLoss(user);
        ArrayList<String> result=new ArrayList<String>();
        result.add(user.getID());
        result.add(user.getWins()+"");
        result.add(user.getLoss()+"");
        return result;
    }
    
    public void quitGame(int id, int room, int desk){
        HallDeskDB db=new HallDeskDB();
        db.QuitGame(id, room, desk);
        db.releaseReady(room, desk);
    }
    
    public void takeGame(int id, int room, int desk){
        HallDeskDB db=new HallDeskDB();
        db.PartakeGame(id, room, desk);
    }
    
    public void getReady(int room, int desk){
        HallDeskDB db=new HallDeskDB();
        db.isReady(room, desk);
        if(db.getDeskInfo(room, desk).getReady()==2){
            GamingStateModel model=new GamingStateModel();
            model.setDeskID(room,desk);
            GamingStateDB gaminDB= new GamingStateDB();
            gaminDB.InsertOption(model);
        }
    }
    
    public void cancelReady(int room, int desk){
        HallDeskDB db=new HallDeskDB();
        db.releaseReady(room, desk);
    }
    
    public ArrayList<Integer> getFreeDeskList(int room){
        System.out.println("Server:"+room);
        HallDeskDB db=new HallDeskDB();
        return db.getFreeDeskList(room);
    }
    
    public void exchangeTurn(int room, int desk){
        HallDeskDB db=new HallDeskDB();
        db.RestartGameExchangeTurn(room, desk);
    }
}